

clear all


foreach d in kenya_ge nigeria bangladesh rwanda colombia sierraleone nepal kenya_iPUSH  kenya_klps drc  { 
	di "------------------      `d'     --------------------"
	qui do "${code}/Data Preparation/dataprep_`d'"
	cap egen highses = cut(ses), group(2)
	if "`d'" == "rwanda" replace highses = ses > 2 if !mi(ses)
	cap egen highage = cut(age), group(2)
	tempfile `d'
	save ``d'', replace
}

use `nepal', clear
gen nepal = 1
append using `kenya_iPUSH', force gen(kenya_iPUSH)
append using `rwanda', force gen(rwanda)
append using `colombia', force gen(colombia)
append using `sierraleone', force gen(sierraleone)
append using `bangladesh', force gen(bangladesh)
append using `nigeria', force gen(nigeria)
append using `kenya_klps', force gen(kenya_klps)
append using `kenya_ge', force gen(kenya_ge)
append using `drc', force gen(drc)


* For now, generating 2 "countries" within nepal so we can have three countries to work with.
*		The random-effects model doesn't make sense with less than 3 "clusters"
*gen ctry = 1*(nepal == 1 & admin1 == 1) + 2*(nepal == 1 & admin1 == 2) + 3*(kenya_iPUSH== 1)
*label define ctry 1 "Nepal - Kailali" 2 "Nepal- Kanchanpur" 3 "Kenya iPUSH"
gen ctry = 1*(nepal == 1) + 2*(kenya_iPUSH== 1) + 3*(rwanda==1 & admin1==3) + 4*(rwanda==1 & admin1==4) ///
	+ 5*(colombia == 1) + 6*(sierraleone == 1) + 7*(bangladesh == 1) + 8*(nigeria == 1) + ///
	9*(rwanda==1 & admin1==2) + 10*(kenya_klps == 1) + 11*(kenya_ge==1) + 12*(drc==1) //+ 5*(rwanda==1 & admin1==3)
replace ctry = . if ctry == 0
label define ctry 1 "Nepal" 2 "Kenya iPUSH" 3 "Rwanda" 4 "Uganda" 5 "Colombia" 6 "Sierra Leone" ///
	7 "Bangaldesh"  8 "Nigeria" 9 "Ghana" 10 "Kenya KLPS" 11 "Kenya GE" 12 "DRC"
label values ctry ctry 
gen ctrytext = "nepal"*(ctry == 1) + "kenyaipush"*(ctry == 2) + "rwanda"*(ctry == 3) + "uganda"*(ctry == 4) ///
	+ "colombia"*(ctry == 5) + "sierraleone"*(ctry == 6) + "bangladesh"*(ctry == 7) + ///
	"nigeria"*(ctry == 8) + "ghana"*(ctry == 9) + "kenyaklps"*(ctry == 10)  + "kenyage"*(ctry == 11) + "drc"*(ctry == 12)
gen country = ctrytext
replace country = "kenya" if regexm(ctrytext, "kenya")
*admin1 labels for Rwanda data:1 "CIV" 2 "GHA" 3 "RWA" 4 "UGA"


gen post = date > mdy(3,22,2020) if !mi(date)
gen mi_depression = mi(___depression_nw)
bysort pid ctry mi_depression (date): gen firstObs = _n == 1 & post == 0 & !mi(___depression_nw)

*tab ctry if firstObs == 1, sum(___depression)
*codebook ___depression if colombia == 1

foreach c in kenyage nigeria bangladesh rwanda colombia sierraleone nepal kenyaipush  kenyaklps drc {
	foreach y in depression  {
		foreach s in _fw _nw _icw {
			di "------    `c'      :     `s'   "
			sum ___`y'`s' if ctrytext == "`c'" & firstObs == 1
			replace ___`y'`s' = (___`y'`s'  -  `r(mean)')/`r(sd)' if ctrytext == "`c'"
		}
	}
}

tab ctry if firstObs == 1, sum(___depression_nw)

egen PID = group(pid ctry)
label var post "Post-Covid time"
label var ___depression_nw "Unweighted Depression Index"
label var ___depression_fw "Factor-Weighted Depression Index"
label var ___depression_icw "Inverse-Covariance-Weighted Depression Index"

tab ctrytext ctry

keep if !mi(date) & !mi(pid) & !mi(ctry)
*bysort ctry pid (date): keep if date[1] < mdy(3,22,2020)

replace ___depression_nw = cesd_score if ctrytext == "kenyaipush"
